<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>back-update</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=0">
    <link rel="stylesheet" href="/admin/layui-v2.4.5/layui/css/layui.css"  media="all">
    <link rel="stylesheet" href="/admin/css/admin.css"  media="all">
    <link rel="stylesheet" href="/admin/css/template.css"  media="all">
    <script src="https://cdn.staticfile.org/jquery/1.10.2/jquery.min.js"></script>
</head>
<body>
<script src="/admin/layui-v2.4.5/layui/layui.js" charset="utf-8"></script>

<div class="layui-fluid" style="padding: 1px "id="testUser" >
    <div class="layui-card">
        <div class="layui-card-header">人员信息</div>
        <div class="layui-card-body" style="padding: 1px;">
            <form class="layui-form"lay-filter="formTestFilter" id="addUserForm">
                <div class="layui-form-item">
                    <label class="layui-form-label">选择科室</label>
                    <div class="layui-input-block">
                        <select name="ofc_id" lay-verify="required" id="departMent" lay-filter="office-select">
                        </select>
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label">管理员账号：</label>
                    <div class="layui-input-block">
                        <input type="text" id="ad_num" name="ad_num" class="layui-input">
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label">管理员密码：</label>
                    <div class="layui-input-block">
                        <input type="text" id="ad_password" name="ad_password" class="layui-input">
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label">管理员备注：</label>
                    <div class="layui-input-block">
                        <input type="text" id="ad_remark" name="ad_remark" class="layui-input">
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label">管理员权限：</label>
                    <div class="layui-input-block">
                        <select class="layui-input" name="ad_power" id="ad_power">
                            <option value="1">超级管理员</option>
                            <option value="0" selected="">普通管理员</option>
                        </select>
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label">管理员姓名：</label>
                    <div class="layui-input-block">
                        <input type="text"id="ad_name" name="ad_name" class="layui-input">
                    </div>
                </div>

                <div class="layui-form-item">
                    <div class="layui-input-block">
                        <button class="layui-btn" lay-submit lay-filter="demo21">立即提交</button>
                        <button type="reset" class="layui-btn layui-btn-primary">重置</button>
                    </div>
                </div>
            </form>
        </div>
    </div>
</div>

<script>

    layui.use('form',function () {
        var form=layui.form;
        form.render('select');
    });


    $(function () {
        fn();
    });

    function fn() {

        $.ajax({
            ansyc: false,
            url: "/hospital/patient/register/office/get",
            type: "GET",
            // contentType:"application/json;charset=utf-8",
            dataType: "json",
            success: function (data) {
                layui.use('form', function () {
                    var form = layui.form;
                    $("#departMent").html("");
                    $("#departMent").append("<option value=''>请选择科室</option>");
                    $.each(data, function (index, ele) {

                        $("#departMent").append("<option value='" + ele.officeId + "'>" + ele.officeName + "</option>");
                    });
                    form.render('select');
                });

            },
            error: function () {
                alert("数据加载失败！");
            }
        });

    }

    layui.use(['layer','form'], function() {
        var $ = layui.$ //由于layer弹层依赖jQuery，所以可以直接得到
            , layer = layui.layer
            , form = layui.form
            ,index = parent.layer.getFrameIndex(window.name)


        form.on('submit(demo21)', function(data){
            // layer.msg(data);
            var value = obj.value //得到修改后的值
                ,data = obj.data //得到所在行所有键值
                ,field = obj.field; //得到字段
            console.log("data"+obj);
            layer.msg('[ID: '+ data.id +'] ' + field + ' 字段更改为：'+ value);
            $.ajax({
                url: "/hospital/updateUser",
                type: "POST",
                dataType: "json",
                contentType: "application/json; charset=utf-8",
                data: JSON.stringify({"id":data.id,
                    "field":field,"value":value}),
                success: function (e) {
                    if (e.code == 1) {
                        layer.msg("修改成功", {time: 1000}, function () {
                            //重新加载父页面
                            table.reload('demo');
                        });
                    } else {
                        layer.msg("更改失败");
                    }
                },
                error: function (e) {
                    layer.msg(e);
                }
            })
            return false;
        });


    })



</script>

</body>
</html>